<?php

/**
 * uniBoard Critical Exception page
 *
 * Light and fast forum solution for web 2.0-like communities.
 *
 * @package		uniBoard
 * @author		Rafał Pitoń
 * @license		http://www.gnu.org/licenses/gpl-3.0.html
 * @since		Version 0.1
 * 
 * ------------------------------------------------------------------------
 * 
 * $Date: 2010-09-06 01:45:14 +0000 (Mon, 06 Sep 2010) $
 * $Revision: 59 $
 * $Author: rafio.xudb@gmail.com $
 */

// ------------------------------------------------------------------------

class exc_critical extends Exception{
	
	/**
	 * Exception type
	 *
	 * @var string
	 */
	
	private $exc_type		= '';
	
	/**
	 * Exception message
	 *
	 * @var string
	 */
	
	private $exc_message	= '';
	
	/**
	 * Exception cause
	 *
	 * @var string
	 */
	
	private $exc_cause		= '';
	
	// ------------------------------------------------------------------------
	
	/**
	 * Exception constructor
	 *
	 * @param string $ext_type
	 * @param string $exc_message
	 */
	
	function __construct( $ext_type, $exc_message, $exc_cause){
		
		// Pass variables from function arguments to in-class variables
		$this -> exc_type		= $ext_type;
		$this -> exc_message	= $exc_message;
		$this -> exc_cause		= $exc_cause;
		
		// Fix type title
		switch ( $this -> exc_type)
		{
			case 'FILE':
				$this -> exc_type = 'Filesystem';
			break;
			
			case 'DB':
				$this -> exc_type = 'Database';
			break;
				
			case 'STYLE':
				$this -> exc_type = 'Style';
			break;
			
			case 'GENERAL':
			default:
				$this -> exc_type = 'General';
			break;
		}
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Returns exception page HTML
	 *
	 * @return string
	 */
	
	function __toString(){
		
		return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>' . $this -> exc_type . ' Error - ' . PRODUCT_NAME . '</title>
<style type="text/css">
<!--
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,input,textarea,p,blockquote,th,td { margin:0; padding:0; }
table { border-collapse:collapse; border-spacing:0; }
fieldset,img { border:0; }
address,caption,cite,code,dfn,em,strong,th,var { font-style:normal; font-weight:normal; }
ol,ul { list-style:none; }
caption,th { text-align:left; }
q:before,q:after { content:\'\'; }
abbr,acronym { border:0; }

BODY{
	background: url(\'./' . IMAGES_PATH. 'exc_page/bg_shade.jpg\') top repeat-x;
	background-color: #2A4B7C;
  	font: 80% Tahoma, Verdana, Arial, Helvetica, sans-serif;
}

h1{
	color: #F2F2F2;
	margin: 6px 4px;
	font-weight: normal;
}

h2{
	margin: 3px 6px;
	margin-top: 6px;
	font-size: 110%
}

p{
	font-size: 105%;
	margin: 4px;
}

a:link, a:active, a:visited{
	color: #D3D7CF;
	font-weight: normal;
	text-decoration: underline;
}

a:hover{
	color: #FFFFFF;
}

#wrapper{
	width: 800px;
	margin: 80px auto;
}

#product_name{
	color: #9CB2C9;
}

#exception_body {
	border-radius: 6px;
	background-color: #FFFFFF;
	box-shadow: 2px 2px 4px #3C495C;
	padding: 8px;
}

#error_source{
	border-radius: 3px;
	background-color: #EEEEEC;
	padding: 6px;
}

#error_cause{
	border-radius: 3px;
	background-color: #FFF7B8;
	padding: 6px;
}

#footer{
	text-align: right;
	padding: 4px 0px;
	color: #D3D7CF;
}

-->
</style>
</head>
<body>
<div id="wrapper">
	<h1>' . $this -> exc_type . ' Error <span id="product_name">' . PRODUCT_NAME . '</span></h1>
	<div id="exception_body">
		<p>' . $this -> exc_message . '</p>
		<h2>Source:</h2>
		<div id="error_source">
			' . $this -> file . ' on line ' . $this -> line . '
		</div>
		<h2>Cause:</h2>
		<div id="error_cause">
			' . $this -> exc_cause . '
		</div>
	</div>
	<div id="footer">powered by <a href="http://uniboard-project.org">' . PRODUCT_NAME . '</a> &copy; ' . date( 'Y' ) . ' by Rafał Pitoń</div>
</div>
</body>
</html>';
		
	}
	
}